<?php
Yii::import('zii.widgets.grid.CGridView');
class NestedSortableGridView extends CGridView {
	
	public $dropDowns;
	
	/**
     * Renders the sorter.
     */
    public function renderItems(){
    	
		$this->dataProvider->debugSql();
		
		$this->runScript();
		
		
		//print_r($this->dataProvider->data);
		
		
		parent::renderItems();
		
	}//end function

	public function runScript(){
		
		$assetsDir=dirname(__FILE__) . DIRECTORY_SEPARATOR . 'assets';
    	$assetsUrl=Yii::app()->assetManager->publish($assetsDir);
		
		Yii::app()->clientScript
			->registerScriptFile($assetsUrl.'/jquery.ui.nestedSortable.js', CClientScript::POS_HEAD)
			->registerScript(__CLASS__,"
				
				$(document).ready(function(){

					$('ol.sortable').nestedSortable({
						disableNesting: 'no-nest',
						forcePlaceholderSize: true,
						handle: 'div',
						helper:	'clone',
						items: 'li',
						maxLevels: 3,
						opacity: .6,
						placeholder: 'placeholder',
						revert: 250,
						tabSize: 25,
						tolerance: 'pointer',
						toleranceElement: '> div'
					});
				});

			", CClientScript::POS_HEAD);

	}//end function
	
}//end class